home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / term / imagen.trm < prev    next >
Encoding:
Text File  |  1993-03-02  |  16.9 KB  |  738 lines

  1. /*
  2.  * $Id: imagen.trm 3.38.2.32 1992/12/04 18:32:51 woo Exp $
  3.  */
  4.  
  5. /* GNUPLOT - imagen.trm */
  6. /*
  7.  * Copyright (C) 1990   
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   Imagen laser printers
  25.  *
  26.  * AUTHORS
  27.  *   Paul E. McKenney, David Kotz
  28.  *   Rewritten/extended by:
  29.  *    Hans Olav Eggestad
  30.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  31.  * 
  32.  */
  33.  
  34. /*
  35.  * Original for direct Imagen output (but retaining many of the
  36.  * LaTeX extensions) by Paul E. McKenney, 1989.
  37.  * Further modified by David Kotz to fit into gnuplot 2.0.
  38.  * Information Science and Technology Division, SRI International,
  39.  * 333 Ravenswood Ave, Menlo Park, CA 94025.
  40.  * Mail to mckenney@sri.com.
  41.  */
  42.  
  43. #include "impcodes.h"
  44.  
  45. #define IMAGEN_PTS_PER_INCH (300)
  46. #define IMAGEN_A4_H  (IMAGEN_PTS_PER_INCH * 83 / 10) /* default is landscape */
  47. #define IMAGEN_A4_W  (IMAGEN_PTS_PER_INCH * 116 / 10)
  48.  
  49. #define IMAGEN_XMAX (IMAGEN_PTS_PER_INCH * 11) /* 10.0 inches */
  50. #define IMAGEN_YMAX (IMAGEN_PTS_PER_INCH * 78 / 10) /* 7.5 inches */
  51.  
  52. static int IMAGEN_Xmax = IMAGEN_XMAX;  /* width in current orientation */
  53. static int IMAGEN_Ymax = IMAGEN_YMAX;
  54.  
  55. #define IMAGEN_FONTSIZE 12
  56. #define IMAGEN_FONT "cour"
  57.  
  58. #define IMAGEN_HTIC (20)
  59. #define IMAGEN_VTIC (20)
  60. #define IMAGEN_VCHAR (IMAGEN_FONTSIZE*5)
  61. #define IMAGEN_HCHAR (IMAGEN_VCHAR/2)
  62.  
  63. unsigned short IMP_gmap[128];
  64. unsigned char IMP_chmap[256];
  65.  
  66. static int IMAGEN_page_h  = IMAGEN_A4_H;
  67. static int IMAGEN_page_w = IMAGEN_A4_W;
  68. static int IM_win_horiz = 1;
  69. static int IM_win_verti = 1;
  70. static int IM_plot_nr = 0;
  71.  
  72. static int IMAGEN_fontsize = IMAGEN_FONTSIZE;
  73. static int IMAGEN_familytable[36];
  74. static int IMAGEN_orgX;        /* absolute-pixel-ORIgin of graph page.    */
  75. static int IMAGEN_orgY;
  76. static int IMAGEN_orgx;        /* absolute-pixel-ORIgin of current graph. */
  77. static int IMAGEN_orgy;
  78. static int IMAGEN_posx;        /* current drawing position (lines).    */
  79. static int IMAGEN_posy;
  80. static int IMAGEN_inplot;
  81. static int IMAGEN_xmax = IMAGEN_XMAX;    /* width of graph in pixels.    */
  82. static int IMAGEN_ymax = IMAGEN_YMAX;    /* height of graph in pixels.    */
  83. static int IMAGEN_winx = IMAGEN_XMAX;    /* width of window in pixels.    */
  84. static int IMAGEN_winy = IMAGEN_YMAX;    /* height of window in pixels.    */
  85. static int IMAGEN_hchar;    /* Height of CHAR in current font.    */
  86. static int IMAGEN_wchar;    /* Width of CHAR in current font.    */
  87. static int IMAGEN_blofs;    /* BaseLine OFfSet from bounding box.    */
  88. static int IMAGEN_angle = -1;    /* 0 for horizontal text, 1 for vertical */
  89. static int IMAGEN_portrait;    /* 0 for landscape */
  90. static enum JUSTIFY IMAGEN_justify = LEFT; /* left/center/right */
  91.  
  92. static IMAGEN_seq_pos;        /* position in sequence */
  93.  
  94. static void IMAGEN_putwd();
  95. static void IMAGEN_createfamily();
  96. static void IMAGEN_setfont();
  97. static void IMAGEN_setpos();
  98. void IMP_set_draw_pattern();
  99. static unsigned char *IMAGEN_cvts();
  100.  
  101. /* char IMPdrpattern[10][10] = { {0}, {30,10,0}, {0}, {10,30,0}, {2,20,0}, 
  102.     {20,10,0}, {30,20,10,20,0}, {30,20,4,10,10,10,4,20,0}, {40,20,0}, {30,15,4,15,0}
  103. };
  104. */
  105.  
  106. char IMPdrpattern[10][10] = { 
  107. /* -2 */ {0}, 
  108. /* -1 */ {1,8,0}, 
  109. /*  0 */ {0}, 
  110. /*  1 */ {16,4,0}, 
  111. /*  2 */ {3,8,0}, 
  112. /*  3 */ {8,8,0}, 
  113. /*  4 */ {16,6,3,6,0}, 
  114. /*  5 */ {16,6,8,6,0}, 
  115. /*  6 */ {16,4,1,4,8,4,1,4,0}, 
  116. /*  7 */ {16,4,1,8,1,4,0}
  117. };
  118.  
  119. IMAGEN_init()
  120. {
  121.     register struct termentry *t = &term_tbl[term];
  122.  
  123.     /* char font[10];    */        /* font name */
  124.  
  125.     IMAGEN_posx = IMAGEN_posy = 0;
  126.  
  127.     IMAGEN_orgX = (IMAGEN_page_w - IMAGEN_Xmax) / 2;
  128.     IMAGEN_orgY = (IMAGEN_page_h - IMAGEN_Ymax) / 2;
  129.  
  130.     IMAGEN_xmax = IMAGEN_winx = (int)(IMAGEN_Xmax / IM_win_horiz);
  131.     IMAGEN_ymax = IMAGEN_winy = (int)(IMAGEN_Ymax / IM_win_verti);
  132.  
  133.     t->xmax = (unsigned int)(IMAGEN_xmax);
  134.     t->ymax = (unsigned int)(IMAGEN_ymax);
  135.  
  136.     fputs("@document(language impress, paper a4)", outfile);
  137.  
  138.     if (IMAGEN_portrait) {
  139.         putc(imP_SET_ABS_V, outfile);
  140.         IMAGEN_putwd(3520);
  141.     }
  142.     putc(imP_SET_HV_SYSTEM, outfile);
  143.     putc(((IMAGEN_portrait?3:0)<<5)|(3<<3)|(IMAGEN_portrait?0:5), outfile);
  144.  
  145.     /* sprintf(font, "cour%02d", IMAGEN_FONTSIZE); */
  146.     IMAGEN_mapsinit();
  147.     IMAGEN_createmap(1,IMP_gmap);
  148.     /* IMAGEN_createfamily(font, IMAGEN_FONTSIZE); */
  149.     IMAGEN_setfont(IMAGEN_fontsize);
  150.  
  151.     IMAGEN_text_angle(0);
  152.  
  153.     putc(imP_SET_ABS_H, outfile);
  154.     IMAGEN_putwd(0);
  155.     putc(imP_SET_ABS_V, outfile);
  156.     IMAGEN_putwd(0);
  157.  
  158.     IMAGEN_linetype(-1);
  159. }
  160.  
  161. IM_page()
  162. {
  163.     putc(imP_ENDPAGE, outfile);
  164.     putc(imP_PAGE, outfile);
  165. }
  166.  
  167. IMAGEN_graphics()
  168. {
  169.     int tmpx, tmpy;
  170.     int xoff, yoff;
  171.  
  172.     if ( IM_plot_nr >= ( IM_win_horiz * IM_win_verti )) {
  173.     IM_page();
  174.     IM_plot_nr = 0;
  175.     }
  176.     IM_plot_nr++;
  177.     tmpx = IMAGEN_orgX + ((IM_plot_nr - 1) % IM_win_horiz) * IMAGEN_winx;
  178.     tmpy = IMAGEN_orgY + ((IM_win_verti - 1) - (int)((IM_plot_nr - 1) / IM_win_horiz)) * IMAGEN_winy;
  179.     IMAGEN_orgx = tmpx + (int)((IMAGEN_winx - IMAGEN_xmax)/2);
  180.     IMAGEN_orgy = tmpy + (int)((IMAGEN_winy - IMAGEN_ymax)/2);
  181. }
  182.  
  183. IMAGEN_options()
  184. {
  185.     extern struct value *const_express();
  186.     extern double real();
  187.     struct value a;
  188.  
  189.     while (!END_OF_COMMAND) {
  190.         if (almost_equals(c_token,"p$ortrait")) {
  191.             IMAGEN_portrait=TRUE;
  192.             IMAGEN_page_h = IMAGEN_A4_W;
  193.             IMAGEN_page_w = IMAGEN_A4_H;
  194.             IMAGEN_Xmax = IMAGEN_YMAX;
  195.             IMAGEN_Ymax = IMAGEN_XMAX;
  196.             c_token++;
  197.         }
  198.         else if (almost_equals(c_token,"l$andscape")) {
  199.             IMAGEN_portrait=FALSE;
  200.             c_token++;
  201.         } else if (equals(c_token,"[")) { /* windows spesified */
  202.             c_token++;
  203.             if (IM_plot_nr>1)
  204.             if (equals(c_token,"]")) {
  205.                 IM_page();
  206.                 c_token++;
  207.                 continue;
  208.             }
  209.             if (END_OF_COMMAND) {
  210.                     int_error("no. windows: [horizontal,vertical] expected",c_token);
  211.             } else if (!equals(c_token,","))  {
  212.                 IM_win_horiz = (int)real(const_express(&a));
  213.             }    
  214.             if (!equals(c_token,","))
  215.                 int_error("',' expected",c_token);
  216.             c_token++;
  217.             if (!equals(c_token,"]")) {
  218.                 IM_win_verti = (int)real(const_express(&a));
  219.              }
  220.             if (!equals(c_token,"]"))
  221.                   int_error("expecting ']'",c_token);
  222.             c_token++;
  223.         } else {
  224.             /* We have font size specified */
  225.             IMAGEN_fontsize = (int)real(const_express(&a));
  226.             if ( IMAGEN_fontsize < 8 ) 
  227.                 IMAGEN_fontsize = 8;
  228.             if ( IMAGEN_fontsize > 15 ) 
  229.                 IMAGEN_fontsize = 15;
  230.         }
  231.     }
  232.     sprintf(term_options,"%d %s [%1d,%1d]",IMAGEN_fontsize,(IMAGEN_portrait)?"portrait":"landscape",IM_win_horiz,IM_win_verti);
  233. }
  234.  
  235.  
  236. IMAGEN_text()
  237. {
  238. }
  239.  
  240. IMAGEN_scale(xs, ys)
  241.     double xs, ys;            /* scaling factors */
  242. {
  243.     register struct termentry *t = &term_tbl[term];
  244.  
  245.     /* we change the table for use in graphics.c and IMAGEN_graphics */
  246.     t->xmax = (unsigned int)(xs * IMAGEN_winx);
  247.     IMAGEN_xmax = t->xmax ;
  248.     t->ymax = (unsigned int)(ys * IMAGEN_winy);
  249.     IMAGEN_ymax = t->ymax ;
  250.  
  251.     return TRUE ;
  252. }
  253.  
  254. #define DRAW_PATTERNS 6
  255.  
  256.  
  257. IMAGEN_linetype(lt)
  258. int lt;
  259. {
  260.     static int lastlinetype = -10;
  261.     int pen, pattern;
  262.  
  263. /* -2: axis
  264.    -1: border
  265.     0: arrow
  266.     1-7: graph
  267. */
  268.     if (lt == -2) {
  269.         pen = 4;
  270.     } else {
  271.         pen = (int) (lt/8)*2;
  272.         if ( pen <= 0 ) pen = 1;
  273.     }
  274.     lt  = (lt % 8) +2;
  275.  
  276.     if (lastlinetype == lt)
  277.      return;
  278.  
  279.     lastlinetype = lt;    
  280.  
  281.     putc(imP_SET_PEN, outfile);
  282.     putc(pen, outfile);
  283.     IMP_set_draw_pattern(lt,pen);
  284. }
  285.  
  286.  
  287. IMAGEN_move(x,y)
  288.     unsigned int x,y;
  289. {
  290.     IMAGEN_posx = x;
  291.     IMAGEN_posy = y;
  292. }
  293.  
  294. IMAGEN_vector(ux,uy)
  295.     unsigned int ux,uy;
  296. {
  297.     /* Create path. */
  298.  
  299.     putc(imP_CREATE_PATH, outfile);
  300.     IMAGEN_putwd(2);
  301.     IMAGEN_putwd(IMAGEN_posx + IMAGEN_orgx);
  302.     IMAGEN_putwd(IMAGEN_posy + IMAGEN_orgy);
  303.     IMAGEN_putwd(ux + IMAGEN_orgx);
  304.     IMAGEN_putwd(uy + IMAGEN_orgy);
  305.  
  306.     /* Draw path with black pen. */
  307.  
  308.     putc(imP_DRAW_PATH, outfile);
  309.     putc(15, outfile);
  310.  
  311.     /* Set current position to end of line. */
  312.  
  313.     IMAGEN_move(ux, uy);
  314. }
  315.  
  316. static void
  317. IMAGEN_setpos(ux, uy)
  318.     int ux,uy;
  319. {
  320.     /* Set x and y position (for text), also set beginning-of-line. */
  321.  
  322.     putc(imP_SET_ABS_H, outfile);
  323.     IMAGEN_putwd(ux + IMAGEN_orgx);
  324.     putc(imP_SET_ABS_V, outfile);
  325.     IMAGEN_putwd(uy + IMAGEN_orgy);
  326.     putc(imP_SET_BOL, outfile);
  327.     if (IMAGEN_angle == 1)
  328.      IMAGEN_putwd(uy + IMAGEN_orgx); /* vertical */
  329.     else
  330.      IMAGEN_putwd(ux + IMAGEN_orgx); /* horizontal */
  331. }
  332.  
  333. IMAGEN_text_angle(angle)
  334.     int angle;
  335. {
  336.     if (IMAGEN_angle != angle) {
  337.        IMAGEN_angle = angle;    /* record for later use */
  338.        putc(imP_SET_ADV_DIRS, outfile);
  339.        putc(angle == 0 ? 0 : 7, outfile); /* 0=>horiz : 7=>vert */
  340.     }
  341.  
  342.     return(TRUE);
  343. }
  344.  
  345. IMAGEN_justify_text(mode)
  346.     enum JUSTIFY mode;
  347. {
  348.     IMAGEN_justify = mode;
  349.     return(TRUE);
  350. }
  351.  
  352. static unsigned char *
  353. IMAGEN_cvts(str, width, height)
  354.     unsigned char        *str;
  355.     int        *width;
  356.     int        *height;
  357. {
  358.     unsigned char        *cp1;
  359.     unsigned char        *cp2;
  360.     static unsigned char    *buf = NULL;
  361.     int        h;
  362.     int        maxw;
  363.     int        w;
  364.  
  365.     /* Free up old buffer, if there is one, get a new one.  Since    */
  366.     /* all transformations shorten the string, get a buffer that is    */
  367.     /* the same size as the input string.                */
  368.  
  369.     if (buf != NULL)
  370.      (void) free(buf);
  371.     buf = (unsigned char *) alloc(strlen(str) + 1, "converted label string");
  372.  
  373.     /* Do the transformations. */
  374.  
  375.     cp1 = str;
  376.     cp2 = buf;
  377.     h = 1;
  378.     maxw = 0;
  379.     w = 0;
  380.     while (strlen(cp1) > 0) {
  381.        switch (*cp1) {
  382.           case ' ' :        /* Space character. */
  383.             *cp2++ = imP_SP;
  384.             w++;
  385.             break;
  386.             
  387.             case  '\\' :    /* Escape sequence. */
  388.              if (*++cp1 == '\\') {
  389.                 /* Begin new line. */
  390.                 h++;
  391.                 if (w > maxw)
  392.                   maxw = w;
  393.                 w = 0;
  394.                 *cp2++ = '\n';
  395.                 /* *cp2++ = imP_CRLF; */
  396.                 break;
  397.              }
  398.             
  399.             /* Fall through to just copy next char out.    */
  400.             
  401.             default :
  402.              /* *cp2++ = *cp1; */
  403.              *cp2++ = IMP_chmap[*cp1];
  404.             w++;
  405.             break;
  406.         }
  407.        cp1++;
  408.     }
  409.     
  410.     *cp2++ = '\n';
  411.     *cp2 = '\0';
  412.     if (w > maxw)
  413.      maxw = w;
  414.     
  415.     if (height != NULL)
  416.      *height = IMAGEN_angle ?
  417.        IMAGEN_wchar * maxw :
  418.         IMAGEN_hchar * h;
  419.     if (width != NULL)
  420.      *width = IMAGEN_angle ?
  421.        IMAGEN_hchar * h :
  422.         IMAGEN_wchar * maxw;
  423.     return (buf);
  424. }
  425.  
  426. IMAGEN_put_text(x, y, str)
  427.     int x,y;                /* reference point of string */
  428.     unsigned char str[];            /* the text */
  429. {
  430.     unsigned char *cvstr, *p; 
  431.     int height;
  432.     int width;
  433.     int sx, sy;
  434.     
  435.     cvstr = IMAGEN_cvts(str, &width, &height);
  436.  
  437.     if (IMAGEN_angle) {        /* vertical */
  438.     /* x += IMAGEN_hchar; */
  439.        x -= width/2 - IMAGEN_hchar;
  440.       /* y -= height/2; */
  441.     } else                /* horizontal */
  442.      y += height/2 - IMAGEN_hchar;
  443.  
  444.     while ( p=(unsigned char *)strchr(cvstr,'\n' )) {
  445.     *p = '\0';
  446.         sx = x;
  447.         sy = y;
  448.         if ( IMAGEN_angle )
  449.         sx = x - IMAGEN_blofs;
  450.         else
  451.         sy = y + IMAGEN_blofs;
  452.     
  453.         width = strlen(cvstr)*IMAGEN_wchar;
  454.     
  455.         switch (IMAGEN_justify) {
  456.            case LEFT: 
  457.             break;
  458.            case CENTRE: 
  459.             if ( IMAGEN_angle ) {
  460.                 sy = y - width/2;
  461.             } else {
  462.                 sx = x - width/2;
  463.             }
  464.             break;
  465.             /*x -= width/2; break; */
  466.            case RIGHT: 
  467.             if ( IMAGEN_angle ) {
  468.                 sy = y - width;
  469.             } else {
  470.                 sx = x - width;
  471.             }
  472.             break;
  473.             /* x -= width; break; */
  474.         }
  475.  
  476.         IMAGEN_setpos(sx, sy);
  477.         fputs((char*) cvstr, outfile);
  478.     cvstr = ++p;
  479.     if (IMAGEN_angle) {     /* vertical */
  480.         x += IMAGEN_hchar;
  481.     } else {
  482.         y -= IMAGEN_hchar;
  483.     }
  484.  
  485.     }
  486. }
  487.  
  488. IMAGEN_reset()
  489. {
  490.     putc(imP_EOF, outfile);
  491. }
  492.  
  493. static void
  494. IMAGEN_putwd(w)
  495. {
  496.     putc(w>>8, outfile);
  497.     putc(w, outfile);
  498. }
  499.  
  500. static void
  501. IMAGEN_createfamily(c, sz)
  502.     char        *c;
  503.     int        sz;
  504. {
  505.  
  506.     putc(imP_CREATE_FAMILY_TABLE, outfile);
  507.     putc(sz, outfile);
  508.     putc(1, outfile);
  509.     putc(1, outfile);
  510.     /* putc(0, outfile); */
  511.     fputs(c, outfile);
  512.     putc(0, outfile);
  513. }
  514.  
  515. static void
  516. IMAGEN_setfont(sz) 
  517.     int sz;
  518. {
  519.     char font[20];
  520.  
  521.     if ( ! IMAGEN_familytable[sz] ) {
  522.     sprintf(font,"%s%02d",IMAGEN_FONT,sz);
  523.     IMAGEN_createfamily(font, sz);
  524.         IMAGEN_familytable[sz] = sz;
  525.     }
  526.     IMAGEN_hchar = sz * 5;
  527.     IMAGEN_wchar = IMAGEN_hchar / 2;
  528.     IMAGEN_blofs = IMAGEN_hchar / 3;
  529.     term_tbl[term].v_char = IMAGEN_hchar;
  530.     term_tbl[term].h_char = IMAGEN_wchar;
  531.     putc(imP_SET_FAMILY, outfile);
  532.     putc(sz, outfile);
  533.     putc(imP_SET_SP, outfile);
  534.     IMAGEN_putwd(IMAGEN_wchar);
  535.     putc(imP_SET_IL, outfile);
  536.     IMAGEN_putwd(IMAGEN_hchar);
  537. }
  538.  
  539. void
  540. IMP_set_draw_pattern(pattern,sz)
  541. int sz, pattern;
  542. {
  543.     int i,j;
  544.     putc(imP_SET_DRAW_PATTERN, outfile);
  545.     putc(0,outfile);
  546.     putc(imP_SET_DRAW_PATTERN, outfile);
  547.     /* if ( strlen(IMPdrpattern[pattern]) == 1 ) {
  548.         putc(type,outfile);
  549.         return;
  550.     } */ 
  551.     putc(strlen(IMPdrpattern[pattern]),outfile);
  552.     for ( i=0;i<strlen(IMPdrpattern[pattern]);i++) {
  553.         IMAGEN_putwd(IMPdrpattern[pattern][i]*sz);
  554.     }
  555. }
  556.  
  557.  
  558. IMAGEN_mapsinit()
  559. {
  560.  
  561.     register int i, j;
  562.  
  563.     for ( i=32;i<127;i++) {
  564.         IMP_gmap[i] = i;
  565.     }
  566.     IMP_gmap[1] = 225;
  567.     IMP_gmap[2]  = 233;
  568.     IMP_gmap[3] = 61736;
  569.     IMP_gmap[4] = 241;
  570.     IMP_gmap[5]  = 249;
  571.     IMP_gmap[6] = 61864;
  572.     IMP_gmap[7] = 162;
  573.     IMP_gmap[8] = 163;
  574.     IMP_gmap[9] = 164;
  575.     IMP_gmap[10] = 165;
  576.     IMP_gmap[11] = 167;
  577.     IMP_gmap[12] = 171;
  578.     IMP_gmap[13] = 182;
  579.     IMP_gmap[14] = 61346;
  580.     IMP_gmap[15] = 191;
  581.     IMP_gmap[16] = 187;
  582.     IMP_gmap[17] = 188;
  583.     IMP_gmap[18] = 189;
  584.     IMP_gmap[19] = 190;
  585.     IMP_gmap[20] = 210;
  586.     IMP_gmap[21] = 211;
  587.     IMP_gmap[22] = 251;
  588.     IMP_gmap[23] = 61232;
  589.     IMP_gmap[24] = 212;
  590.     IMP_gmap[25] = 137;
  591.     IMP_gmap[26] = 176;
  592.     IMP_gmap[27] = 161;
  593.     IMP_gmap[28] = 139;
  594.     IMP_gmap[29] = 133;
  595.     IMP_gmap[30] = 140;
  596.     IMP_gmap[31] = 61249;
  597.     IMP_gmap[32] = 8738;
  598.     IMP_gmap[34] = 186;
  599.     IMP_gmap[36] = 164;
  600.     IMP_gmap[39] = 185;
  601.     IMP_gmap[127] = 61286;
  602.  
  603.     /* for (i=1;i<127;i++) fprintf(stderr,"%d -> %d\n",i,IMP_gmap[i]); */
  604.  
  605.     for ( i=32;i<=127;i++) {
  606.         IMP_chmap [i] = i;
  607.     }
  608.     for ( i=128;i<=255;i++) {
  609.         IMP_chmap [i] = 128; /* first map all non printable chars to SPACE */
  610.     }
  611.  
  612.     IMP_chmap [161] = 27;
  613.     IMP_chmap [162] = 7;
  614.     IMP_chmap [163] = 8;
  615.     IMP_chmap [164] = 120;
  616.     IMP_chmap [165] = 10;
  617.     IMP_chmap [166] = 124;
  618.     IMP_chmap [167] = 11;
  619.     IMP_chmap [168] = 25;
  620.     IMP_chmap [169] = 21;
  621.     IMP_chmap [170] = 45;
  622.     IMP_chmap [171] = 12;
  623.     IMP_chmap [172] = 83;
  624.     IMP_chmap [173] = 45;
  625.     IMP_chmap [174] = 20;
  626.     IMP_chmap [175] = 126;
  627.     IMP_chmap [176] = 26;
  628.     IMP_chmap [177] = 12;
  629.     IMP_chmap [178] = 1;
  630.     IMP_chmap [179] = 2;
  631.     IMP_chmap [180] = 29;
  632.     IMP_chmap [181] = 52;
  633.     IMP_chmap [182] = 13;
  634.     IMP_chmap [183] = 5;
  635.     IMP_chmap [184] = 28;
  636.     IMP_chmap [185] = 3;
  637.     IMP_chmap [186] = 45;
  638.     IMP_chmap [187] = 16;
  639.     IMP_chmap [188] = 17;
  640.     IMP_chmap [189] = 18;
  641.     IMP_chmap [190] = 19;
  642.     IMP_chmap [191] = 15;
  643.     IMP_chmap [192] = 65;
  644.     IMP_chmap [193] = 65;
  645.     IMP_chmap [194] = 65;
  646.     IMP_chmap [195] = 65;
  647.     IMP_chmap [196] = 65;
  648.     IMP_chmap [197] = 3;
  649.     IMP_chmap [198] = 1;
  650.     IMP_chmap [199] = 67;
  651.     IMP_chmap [200] = 69;
  652.     IMP_chmap [201] = 69;
  653.     IMP_chmap [202] = 69;
  654.     IMP_chmap [203] = 69;
  655.     IMP_chmap [204] = 73;
  656.     IMP_chmap [205] = 73;
  657.     IMP_chmap [206] = 73;
  658.     IMP_chmap [207] = 73;
  659.     IMP_chmap [208] = 68;
  660.     IMP_chmap [209] = 78;
  661.     IMP_chmap [210] = 79;
  662.     IMP_chmap [211] = 79;
  663.     IMP_chmap [212] = 79;
  664.     IMP_chmap [213] = 79;
  665.     IMP_chmap [214] = 79;
  666.     IMP_chmap [215] = 13;
  667.     IMP_chmap [216] = 2;
  668.     IMP_chmap [217] = 85;
  669.     IMP_chmap [218] = 85;
  670.     IMP_chmap [219] = 85;
  671.     IMP_chmap [220] = 85;
  672.     IMP_chmap [221] = 89;
  673.     IMP_chmap [222] = 32;
  674.     IMP_chmap [223] = 22;
  675.     IMP_chmap [224] = 97;
  676.     IMP_chmap [225] = 97;
  677.     IMP_chmap [226] = 97;
  678.     IMP_chmap [227] = 97;
  679.     IMP_chmap [228] = 97;
  680.     IMP_chmap [229] = 6;
  681.     IMP_chmap [230] = 4;
  682.     IMP_chmap [231] = 99;
  683.     IMP_chmap [232] = 101;
  684.     IMP_chmap [233] = 101;
  685.     IMP_chmap [234] = 101;
  686.     IMP_chmap [235] = 101;
  687.     IMP_chmap [236] = 105;
  688.     IMP_chmap [237] = 105;
  689.     IMP_chmap [238] = 105;
  690.     IMP_chmap [239] = 105;
  691.     IMP_chmap [240] = 100;
  692.     IMP_chmap [241] = 110;
  693.     IMP_chmap [242] = 111;
  694.     IMP_chmap [243] = 111;
  695.     IMP_chmap [244] = 111;
  696.     IMP_chmap [245] = 111;
  697.     IMP_chmap [246] = 111;
  698.     IMP_chmap [247] = 10;
  699.     IMP_chmap [248] = 5;
  700.     IMP_chmap [249] = 117;
  701.     IMP_chmap [250] = 117;
  702.     IMP_chmap [251] = 117;
  703.     IMP_chmap [252] = 117;
  704.     IMP_chmap [253] = 121;
  705.     IMP_chmap [254] = 32;
  706.     IMP_chmap [255] = 121;
  707. }
  708.  
  709. IMAGEN_createmap(name,map) 
  710. unsigned short *map; 
  711. int name; 
  712.     register int i,j; 
  713.     unsigned char s[4], *p; 
  714.  
  715.     p = s; 
  716.     *p++ = imP_CREATE_MAP; 
  717.     *p++ = name; 
  718.     j = 0; 
  719.     for (i=0;i<127;i++) { 
  720.         if ( map[i] ) j++; 
  721.     } 
  722.     *p = j; 
  723.     for (i=0;i<3;i++) putc(s[i],outfile); 
  724.  
  725.     s[3] = 1;
  726.     for (j=0;j<127;j++) { 
  727.         if ( map[j] ) { 
  728.             p = s; 
  729.             *p++ = j; 
  730.             *p++ = map[j] >> 8; 
  731.             *p   = map[j] & 255;
  732.             for (i=0;i<4;i++) putc(s[i],outfile); 
  733.         } 
  734.     } 
  735.  
  736.